package com.ruoyi.business.controller;


import com.ruoyi.business.service.IWsdLeaveTypesService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.WsdLeaveTypes;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 请假类型表 前端控制器
 * </p>
 *
 * @author wwq
 * @since 2024-05-08
 */
@Controller
@RequestMapping("/wsd_leave_types")
public class WsdLeaveTypesController extends BaseController {

    @Autowired
    private IWsdLeaveTypesService wsdLeaveTypesService;

    /**
     * 查询请假类型列表
     */
    @PreAuthorize("@ss.hasPermi('business:types:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdLeaveTypes wsdLeaveTypes)
    {
        startPage();
        List<WsdLeaveTypes> list = wsdLeaveTypesService.selectWsdLeaveTypesList(wsdLeaveTypes);
        return getDataTable(list);
    }


    /**
     * 获取请假类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:types:query')")
    @GetMapping(value = "/{leaveTypeId}")
    public AjaxResult getInfo(@PathVariable("leaveTypeId") Long leaveTypeId)
    {
        return success(wsdLeaveTypesService.selectWsdLeaveTypesByLeaveTypeId(leaveTypeId));
    }

    /**
     * 新增请假类型
     */
    @PreAuthorize("@ss.hasPermi('business:types:add')")
    @Log(title = "请假类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdLeaveTypes wsdLeaveTypes)
    {
        return toAjax(wsdLeaveTypesService.insertWsdLeaveTypes(wsdLeaveTypes));
    }

    /**
     * 修改请假类型
     */
    @PreAuthorize("@ss.hasPermi('business:types:edit')")
    @Log(title = "请假类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WsdLeaveTypes wsdLeaveTypes)
    {
        return toAjax(wsdLeaveTypesService.updateWsdLeaveTypes(wsdLeaveTypes));
    }

    /**
     * 删除请假类型
     */
    @PreAuthorize("@ss.hasPermi('business:types:remove')")
    @Log(title = "请假类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{leaveTypeIds}")
    public AjaxResult remove(@PathVariable Long[] leaveTypeIds) {
        return toAjax(wsdLeaveTypesService.deleteWsdLeaveTypesByLeaveTypeIds(leaveTypeIds));
    }

}
